﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace QLKS.Views
{
    /// <summary>
    /// Interaction logic for ucDmNhanvien.xaml
    /// </summary>
    public partial class ucDmNhanVien : UserControl
    {
        string columns = "tennv,ngaysinh,gioitinh,diachi,email,ghichu,hinhanh,manv,cmnd,macv,dienthoai";
        public ucDmNhanVien()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            mainContent.StringBrowse = "tennv:Họ tên:200:F;ngaysinh:Ngày sinh:150;gioitinh:Giới tính:70;diachi:Địa chỉ:250;email:Email:200;ghichu:Ghi chú:250;hinhanh:Hình ảnh:0:IV;manv:mã nv:0:IV;cmnd:cmnd:0:IV;macv:chức vụ:0:IV;dienthoai:điện thoại:0:IV";
            mainContent.TableSource = ViewModels.NhanVienViewModel.GetAllNhanVien(columns);
            mainContent.F2 += new ucDmTemplate.GridKeyUp_F2(PressKey_F2);//Xem
            mainContent.F4 += new ucDmTemplate.GridKeyUp_F4(PressKey_F4);//Tạo mới
            mainContent.F3 += new ucDmTemplate.GridKeyUp_F3(PressKey_F3);//Chỉnh sửa
            mainContent.F7 += new ucDmTemplate.GridKeyUp_F7(PressKey_F7);//Copy
            mainContent.F6 += new ucDmTemplate.GridKeyUp_F6(PressKey_F6);//Refresh
            mainContent.F8 += new ucDmTemplate.GridKeyUp_F8(PressKey_F8);//Delete
        }

        void PressKey_F2(object sender, EventArgs e)
        {
            DataTable tb = mainContent.CurentRow;
            if (tb == null)
                return;
            frmThemNhanVien frm = new frmThemNhanVien(tb,Command.View);
            frm.Show();
        }

        void PressKey_F3(object sender, EventArgs e)
        {
            DataTable tb = mainContent.CurentRow;
            if (tb == null)
                return;
            frmThemNhanVien frm = new frmThemNhanVien(tb, Command.Edit);
            frm.Show();
            if (frm.UpdateSucces)
                mainContent.Update(ViewModels.NhanVienViewModel.GetAllNhanVien(columns));
        }
        void PressKey_F8(object sender, EventArgs e)
        {
            DataTable tb = mainContent.CurentRow;
            if (tb == null)
                return;
            ViewModels.PhongViewModel.XoaPhong(tb.Rows[0]["manv"].ToString());
        }
        void PressKey_F4(object sender, EventArgs e)
        {
            frmThemNhanVien frm = new frmThemNhanVien(null,Command.New);
            frm.ShowDialog();
            if (frm.UpdateSucces)
                mainContent.Update(ViewModels.NhanVienViewModel.GetAllNhanVien(columns));
        }
        void PressKey_F7(object sender, EventArgs e)
        {
            DataTable tb = mainContent.CurentRow;
            if (tb == null)
                return;
            frmThemNhanVien frm = new frmThemNhanVien(tb, Command.Copy);
            frm.Show();
            if (frm.UpdateSucces)
                mainContent.Update(ViewModels.NhanVienViewModel.GetAllNhanVien(columns));
        }

        void PressKey_F6(object sender, EventArgs e)
        {
            mainContent.Update(ViewModels.NhanVienViewModel.GetAllNhanVien(columns));
        }
    }
}
